﻿#include "receiver.h"

Receiver::Receiver(QObject *parent) :
    QObject(parent)
{
    receiver=new QUdpSocket(this);
    receiver->bind(RECV_PORT,QUdpSocket::ShareAddress);
    connect(receiver,&QUdpSocket::readyRead,this,&Receiver::processPendingDatagram);
}

void Receiver::processPendingDatagram()
{
    while(receiver->hasPendingDatagrams())
    {
        QByteArray data;
        data.resize(receiver->pendingDatagramSize());
        receiver->readDatagram(data.data(),data.size());

        QDataStream in(&data,QIODevice::ReadOnly);
        in >> title >> content >> type >> part;
        emit received();
    }
}
